package com.weiyuwqj.controller.loan;

import com.weiyuwqj.api.common.PageList;
import com.weiyuwqj.api.common.Paginator;
import com.weiyuwqj.api.constant.Constants;
import com.weiyuwqj.api.exception.CrowdException;
//import com.weiyuwqj.api.model.BusLoan;
import com.weiyuwqj.api.model.SysTempcode;
import com.weiyuwqj.api.service.BasItemService;
import com.weiyuwqj.api.service.BusInvestRepayService;
//import com.weiyuwqj.api.service.BusLoanService;
//import com.weiyuwqj.api.service.SysAreasService;
import com.weiyuwqj.api.util.IpUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/7/11 0011.
 */
@Controller
@RequestMapping("loan")
public class LoanController {
/*

    @Autowired
    BasItemService basItemService;
    @Autowired
    BusInvestRepayService busInvestRepayService;

    */
/**
     * 添加
     * @param busLoan
     * @param request
     * @return
     *//*

    @ResponseBody
    @RequestMapping(value = "/addLoan")
    public Object addLoan(BusLoan busLoan,String mobileCode,HttpServletRequest request){
        Long validPhoneExpiredTime = (Long) request.getSession().getAttribute("validPhoneExpiredTime");
        Object validPhoneCode=request.getSession().getAttribute("validPhoneCode");
        if(validPhoneCode==null){
            throw new CrowdException("user.register.randomCode.no");
        }

        //发送短信
        Date now = new Date();
        long between = (now.getTime() - validPhoneExpiredTime) / 1000;

        if (!(validPhoneCode.equals(mobileCode))) {
            throw new CrowdException("user.register.randomCode.error");
        }
        if (between > Constants.VALIDATETIME) {
            throw new CrowdException("user.register.randomCode.timeout");
        }

        busLoan.setStatus(1);
        busLoan.setUserId((Integer)request.getSession().getAttribute("userId"));
        busLoan.setAddtime(new Date());
        busLoan.setAddip(IpUtils.get());
        return busLoanService.save(busLoan);
    }

    */
/**
     * 地区查询
     * @return
     *//*

    @ResponseBody
    @RequestMapping(value = "/areaList")
    public Object provinceList(Integer pid){
        Map map=new HashMap();
        map.put("pid",pid);
        return sysAreasService.getProvinceList(map);
    }

    */
/**
     * 我的借款,已申请
     *//*

    @ResponseBody
    @RequestMapping(value = "/alreadyApply")
    public Object alreadyApply(Paginator p,HttpServletRequest request){
        Integer userId=(Integer)request.getSession().getAttribute("userId");
        Map map=new HashMap();
        map.put("userId",userId);
        PageList list= busLoanService.getMyLoanList(p, map);
        return list;

    }

    */
/**
     * 我的借款,已发布
     *//*

    @ResponseBody
    @RequestMapping(value = "/alreadyRelease")
    public Object alreadyRelease(Paginator p,HttpServletRequest request){
        Integer userId=(Integer)request.getSession().getAttribute("userId");
        Map map=new HashMap();
        map.put("userId",userId);
        return basItemService.getLoanItemList(p,map);
    }

    */
/**
     * 还款明细
     *//*

    @ResponseBody
    @RequestMapping(value = "/repaymentDetails")
    public Object repaymentDetails(Paginator p,HttpServletRequest request){
        Integer userId=(Integer)request.getSession().getAttribute("userId");
        Map map=new HashMap();
        map.put("userId",userId);
        return busInvestRepayService.getRepaymentList(p,map);
    }

    */
/**
     * 贷款统计
     * @param
     * @return
     *//*

    @ResponseBody
    @RequestMapping(value = "/repaymentStatistics")
    public Object repaymentStatistics(HttpServletRequest request){
        Integer userId=(Integer)request.getSession().getAttribute("userId");
        Map map=new HashMap();
        map.put("userId",userId);
        return basItemService.getRepaymentStatistics(map);
    }
*/

}
